<template>
	<view class="logistics">
		<view class="top" v-if="data.list.length">
			<view class="top_1">
				您的订单分成多个包裹发出：
				<view class="" >
					<view  class="topItem" :class="data.index == index?'active':''" @tap="data.index = index,data.emsInfoDTOS = item" v-for="(item,index) in data.list" :key="index">
						<view class="left">
							包裹({{index+1}})
							<text>共1件</text>
						</view>
						<view class="right">
							<image :src="item.expressCompanyLogo" mode="aspectFill"></image>
						</view>
					</view>
				</view>

			</view>
			<view class="top_2">
				<view class="top">
					<image src="/static/img/index/135.png" mode="widthFix"></image>
					{{data.list[data.index].logisticsStatusDesc}}
				</view>
				{{data.list[data.index].theLastMessage}}
			</view>
			<view class="bot">
				<view class="">
					承运人：
					<view class="">
						{{data.list[data.index].expressCompanyName}}
					</view>
				</view>
				<view class="">
					运单号：
					<view class="">
						{{data.list[data.index].number}}
						<image src="/static/img/index/133.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="process"  v-if="data.list.length">
			<view class="itemTop">
				<image src="/static/img/index/135.png" mode="widthFix"></image>
				{{data.list[data.index].logisticsStatusDesc}}
			</view>
			<view class="item" :class="index == 0?'item1':''" v-for="(item,index) in data.list[data.index].logisticsTraceDetails" :key="index">
				<view class="left">
					<view></view>
				</view>
				<view class="right">
					<view class="">
						<text class="ellipsis_2">{{item.desc}}</text>
						<text class="ellipsis_1">{{item.timeFormat}}</text>
					</view>
				</view>
			</view>
			<view  :class="item.logisticsStatus == '已发货'?'fh':'xd'" v-for="(item,index) in data.list[data.index].startTraceDetails" :key="index">
				<view class="left">
					<image :src="item.logisticsStatus == '已发货'?'/static/img/index/134.png':'/static/img/index/136.png'" mode="widthFix"></image>
				</view>
				<view class="right">
					{{item.logisticsStatus}}
					<view class="">
						<text  class="ellipsis_2">{{item.desc}}</text>
						<text class="ellipsis_1">{{item.timeFormat}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="zanwu" v-if="!data.list.length">
			暂无物流
		</view>
	</view>
</template>

<script setup lang="ts">
	import { onLoad } from '@dcloudio/uni-app';
	import { queryEmsByGroupOrder,queryRefundBuyerLogistics,queryEmsBySonOrder } from '@/utils/api/goods'
	import { reactive } from 'vue';
	const data = reactive<any>({
		info:{},
		index:0,
		list:[]
	})
	onLoad(({ id,refundNo,logisticsNo,isMj}) => {
		if(isMj){
			//卖家订单物流
			queryEmsBySonOrder({data:{sonOrderNo:id}}).then((res)=>{
				data.list = res.data;
			})
		}else{
			if(refundNo){
				//退款物流
				queryRefundBuyerLogistics({data:{refundNo,logisticsNo}}).then((res)=>{
					data.list = res.data;
				})
			}else{
				//订单物流
				queryEmsByGroupOrder({ data: { groupOrderNo: id } }).then((res) => {
					data.list = res.data;
				})
			}
		}
		
		
	})
</script>

<style lang="scss">
	.zanwu{
		margin-top: 320rpx;
		text-align: center;
		font-size: 40rpx;
	}
	.process {
		padding: 32rpx 24rpx;
		border-radius: 24rpx;
		background: #fff;
		margin-top: 24rpx;

		.itemTop {
			display: flex;

			image {
				width: 48rpx;
				margin-right: 24rpx;
			}

			font-size: 32rpx;
		}

		.xd {
			margin-top: 66rpx;

			.left {
				&:before {
					width: 2rpx;
					background: #E5E5E5;
					height: 170rpx;
					display: inline-block;
					content: '';
					position: absolute;
					left: 23rpx;
					top: -170rpx;
					z-index: 8;
				}
			}
		}

		.item1 {
			.left {

				&:before {
					height: 84rpx !important;

					top: -84rpx !important;
				}
			}
		}

		.item {
			align-items: center !important;

			.left {
				width: 48rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				view {
					width: 12rpx;
					height: 12rpx;
					border-radius: 12rpx;
					background: #D9D9D9;
				}

				&:before {
					width: 2rpx;
					background: #E5E5E5;
					height: 170rpx;
					display: inline-block;
					content: '';
					position: absolute;
					left: 23rpx;
					top: -170rpx;
					z-index: 8;
				}
			}
		}

		.fh {
			margin-top: 36rpx;
		}

		.fh,
		.xd,
		.item {
			display: flex;
			align-items: flex-start;

			.left {
				margin-right: 24rpx;
				position: relative;

				image {
					width: 48rpx;
				}
			}

			.right {
				flex: 1;
				font-size: 32rpx;
				height: 180rpx;
				view {
					display: flex;
					flex-direction: column;
					margin-top: 16rpx;
					padding: 16rpx;
					border-radius: 16rpx;
					background: #F5F5F5;

					text:nth-of-type(1) {
						color: #595959;
					}

					text:nth-of-type(2) {
						color: #8C8C8C;
						margin-top: 10rpx;
					}
				}
			}
		}
	}

	.logistics {
		height: 100vh;
		background: #F5F5F5;
		padding: 24rpx;

		>.top {
			padding: 24rpx;
			border-radius: 24rpx;
			background: #fff;

			.bot {
				>view {
					display: flex;
					align-items: center;
					justify-content: space-between;
					color: #8C8C8C;
					margin-top: 20rpx;

					view {
						display: flex;
						align-items: center;

						image {
							width: 28rpx;
							margin-left: 10rpx;
						}
					}
				}
			}

			.top_1 {
				font-size: 24rpx;
				padding-bottom: 32rpx;
				border-bottom: 2rpx dashed #F0F0F0;
				margin-bottom: 32rpx;

				>view {
					display: flex;

				}

				.topItem {
					display: flex;
					align-items: center;
					padding: 14rpx 21rpx;
					border-radius: 16rpx;
					border: 2rpx solid #F0F0F0;
					margin-top: 24rpx;
					margin-right: 24rpx;

					.left {
						display: flex;
						flex-direction: column;
						font-size: 32rpx;

						text {
							color: #BFBFBF;
							font-size: 24rpx;
						}
					}

					.right {
						width: 96rpx;
						height: 96rpx;
						margin-left: 32rpx;
						border-radius: 8rpx;
						background: #ccc;
						
						image{
							border-radius: 8rpx;
							width: 100%;
							height: 100%;
						}
					}
				}
				.active{
					.left{
						color: #6B64D3;
					}
					border-color:  #6B64D3;
				}
			}

			.top_2 {
				color: #8C8C8C;
				padding-bottom: 32rpx;
				border-bottom: 2rpx dashed #F0F0F0;

				.top {
					margin-bottom: 12rpx;
					display: flex;
					align-items: center;
					font-size: 32rpx;

					image {
						width: 48rpx;
						margin-right: 10rpx;
					}
				}
			}
		}
	}
</style>